package com.dmall.chapter06.section05;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class LeetCode1 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int minus = target - nums[i];
            if (map.containsKey(minus)) {
                Integer index = map.get(minus);
                int[] result = new int[2];
                result[0] = index;
                result[1] = i;
                return result;
            }
            map.put(nums[i], i);
        }
        return null;
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 22;
        LeetCode1 leetCode1 = new LeetCode1();
        int[] result = leetCode1.twoSum(nums, target);
        System.out.println(Arrays.toString(result));
    }
}
